package com.newhis.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
public class DruidConfig {
    private static final Logger log = LoggerFactory.getLogger(DruidConfig.class);
    @Value(value = "${jdbc.driver}")
    private String driverClass;
    @Value(value = "${jdbc.url}")
    private String url;
    @Value(value = "${jdbc.username}")
    private String username;
    @Value(value = "${jdbc.password}")
    private String password;
    @Value(value = "${druid.username}")
    private String loginUsername;
    @Value(value = "${druid.password}")
    private String loginPassword;
    @Value(value = "${jdbc.initialSize}")
    private int initialSize = 30;
    @Value(value = "${jdbc.maxAcitve}")
    private int maxAcitve = 100;
    @Value(value = "${jdbc.minIdle}")
    private int minIdle = 30;
    @Value(value = "${jdbc.maxWait}")
    private int maxWait = 100;
    @Value(value = "${jdbc.validationQuery}")
    private String validationQuery;
    @Bean
    public DataSource dataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(this.driverClass);
        dataSource.setUrl(this.url);
        dataSource.setUsername(this.username);
        dataSource.setPassword(this.password);
        dataSource.setInitialSize(this.initialSize);
        dataSource.setMaxActive(this.maxAcitve);
        dataSource.setMinIdle(this.minIdle);
        dataSource.setMaxWait(this.maxWait);
        dataSource.setValidationQuery(this.validationQuery);
        return dataSource;
    }
}
